package com.hqyj.service.impl;

import com.hqyj.dao.ReserveMapper;
import com.hqyj.dao.TableMenuMapper;
import com.hqyj.pojo.TableMenu;
import com.hqyj.service.TableMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@Service
public class TableMenuServiceImpl implements TableMenuService {

    @Autowired
    private TableMenuMapper dao;

    @Autowired
    private ReserveMapper reserveMapper;

    //查看我的点餐
    public HashMap<String, Object> myMenuList(TableMenu tableMenu) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        int i = reserveMapper.selectIdByUserAndState(tableMenu.getUserId());
        tableMenu.settId(i);
        List<TableMenu> list = dao.myList(tableMenu.gettId());
        System.out.println(list);
        if (list.size() > 0) {
            map.put("info", list);
        }else {
            map.put("info", "你未点餐");
        }
        return map;
    }

    //结账
    public HashMap<String, Object> checkout(String arrId) {
        HashMap<String, Object> map = new HashMap<String, Object>();

        if (arrId != null) {
            String ids[] = arrId.split(",");
            if (ids.length == 1) {
                List<String> list = Arrays.asList(ids);
                System.out.println(list);
                int num = dao.myCheck(list);

                if (num > 0) {
                    map.put("info", "结账成功");
                } else {
                    map.put("info", "结账失败");
                }
            } else {
                String id[] = new String[ids.length - 1];
                for (int i = 1; i < ids.length; i++) {
                    id[i - 1] = ids[i];
                }
                List<String> list = Arrays.asList(id);

                //数组转集合
                System.out.println(list);
                int num = dao.myCheck(list);
                if (num > 0) {
                    map.put("info", "结账成功");
                } else {
                    map.put("info", "结账失败");
                }
            }

        }
        return map;
    }

    public HashMap<String, Object> cook(String arrId) {
        HashMap<String, Object> map = new HashMap<String, Object>();

        if (arrId != null) {
            String ids[] = arrId.split(",");
            if (ids.length == 1) {
                List<String> list = Arrays.asList(ids);
                System.out.println(list);
                int num = dao.cook(list);
                if (num > 0) {
                    map.put("info", "制作完毕");
                } else {
                    map.put("info", "制作失败");
                }
            } else {
                String id[] = new String[ids.length - 1];
                for (int i = 1; i < ids.length; i++) {
                    id[i - 1] = ids[i];
                }
                List<String> list = Arrays.asList(id);

                //数组转集合
                System.out.println(list);
                int num = dao.cook(list);
                if (num > 0) {
                    map.put("info", "制作完毕");
                } else {
                    map.put("info", "制作失败");
                }
            }

        }
        return map;
    }

    public HashMap<String, Object> myCook(TableMenu tableMenu) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        tableMenu.settEState("待上菜");
        List<TableMenu> list = dao.myCook(tableMenu.gettEState());
        map.put("info", list);
        return map;
    }

    public HashMap<String, Object> moneyList(TableMenu tableMenu) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        tableMenu.settECheck("已付款");
        List<TableMenu> list = dao.selectMoneyByCheck(tableMenu);
        if (list.size() > 0) {
            map.put("info", list);
        } else {
            map.put("info", "还没有收入");
        }

        return map;
    }

//    public Integer Money(TableMenu tableMenu) {
//        int i = dao.priceMoney(tableMenu);
//
//        return i;
//    }
}
